<?php

namespace Trawind\Rocketmq;

use Illuminate\Queue\QueueManager;
use Illuminate\Support\ServiceProvider;
use Trawind\Rocketmq\Commands\ListenCommand;
use Trawind\Rocketmq\Commands\WorkCommand;
use Trawind\Rocketmq\Queue\Connectors\RocketMQConnector;

class RocketMQServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->commands(WorkCommand::class);
        $this->commands(ListenCommand::class);
        
        $this->mergeConfigFrom(
            __DIR__.'/assets/rocketmq.php', 'queue.connections.rocketmq'
        );
    }

    /**
     * Register the application's event listeners.
     *
     * @return void
     */
    public function boot()
    {
        /** @var QueueManager $queue */
        $queue = $this->app['queue'];

        $queue->addConnector('rocketmq', function () {
            return new RocketMQConnector();
        });
    }
}
